<?php
namespace Crm\Domain;

use Crm\Common\MetaData as MetaData;
use Crm\Common\Util as Util;
use Crm\Common\Pager as Pager;

class SysLog
{
	/**
	 * pdo连接。
	 * 
	 * @var object
	 * @access pdo
	 */
	public $pdo;

    public $metaData;
    public $baseCode;
    public $city_code;
    public $provinceCode;

    public function __construct()
    {
        $this->pdo = \PhalApi\DI()->pdo;
        $this->baseCode = (object)\PhalApi\DI()->config->get('basecode');
        $this->province_code = \PhalApi\DI()->config->get('app.provinceCode');//省
        $this->city_code = \PhalApi\DI()->config->get('app.cityCode');//城市

        $this->metaData = new MetaData();

    }

    /*
     * 记录操作日志
     * $id 操作对象id
     * $text 描述信息
     * $param_name 参数
     */
    public function actionLog($id,$user_id,$text='',$module='',$method='',$param_name=''){
        $user = $this->pdo->getRow("select id,user_name,true_name,user_type,is_admin from sys_user where id={$user_id}");
        $data['action_id'] = $id;
        $data['create_uid'] = $user_id;
        $data['create_date'] = time();
        $data['module'] = $module;
        $data['action'] = $method;
        $data['origin'] = 'miniProject';

        if(!empty($param_name)){
            $data['param'] = strtolower($param_name);
        }

        $data['content'] = implode('',array($user['true_name'].'于', date('Y-m-d H:i:s').'在App端', $text));
        if($this->pdo->add($data,'sys_action_log')){
            $lastId = $this->pdo->getLastInsId();
            return $lastId;
        }else{
            return false;
        }
    }
}
